import axios from 'axios'
import { Toast } from 'vant'

axios.defaults.withCredentials = true
axios.defaults.crossDomain = true
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'

const service = axios.create({
  timeout: 30000
})

service.interceptors.request.use(
  // config =>{
  //     console.log(config)
  // },
  // err =>{

  // }
)

service.interceptors.response.use(
  response => {
    if (response.data.Code === 200) {
      return response.data
    } else {
      Toast({
        message: '请求错误',
        icon: 'cross'
      })
    }
  },
  error => {
    if (error.response) {
      Toast({
        message: '请求错误',
        icon: 'cross'
      })
    }
  }
)
export default service
